package com.example.mq;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 消息生产者
 */
@Component
public class RabbitProvider {

    @Autowired
    private AmqpTemplate amqpTemplate;

    /**
     * 将消息发送到队列中
     */
    public void send() {
        // 将 Hello World 消息，发送到名为 helloRabbit 的队列上去
        amqpTemplate.convertAndSend("HelloRabbit", "Hello World");

        System.out.println("消息发送队列成功。");
    }


}
